package com.ydj.framework.mysql;

import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;

/**
 * Mysql查询,带有逻辑删除的基类
 *
 * @author rick
 */
public class BaseLogicDeleteQuery<T extends BaseLogicDeleteEntity> extends BaseQuery<T> {

    protected Boolean del = false;

    public BaseLogicDeleteQuery(IService<T> service) {
        super(service);
    }

    /**
     * 逻辑删除的标志
     * @param del 为null=全部查询，false=正常查询(默认)，true=查询那些已经删除的
     */
    public BaseLogicDeleteQuery<T> del(Boolean del) {
        this.del = del;
        return this;
    }

    private void addDelIntoSql() {
        if (del != null) {
            eq("del", del ? 1 : 0);
        }
    }

    @Override
    public T single() {
        addDelIntoSql();
        return super.single();
    }

    @Override
    public List<T> list() {
        addDelIntoSql();
        return super.list();
    }

    @Override
    public List<T> page(PageArgs pageArgs) {
        addDelIntoSql();
        return super.page(pageArgs);
    }

    @Override
    public long count() {
        addDelIntoSql();
        return super.count();
    }
}